class Solution {
public:
    void moveZeroes(vector<int>& nums) {
    int cur = 0;
    int dest = -1;
    //先分成两块 一块是 [0 - cur-1] 一块是 [cur - n]
    //再用dest把 [0-cur-1]分为两块 一块是非0元素 一块是0元素[0-dest] [dest+1 - cur-1] [cur - n]
    while(cur<nums.size())
    {
        if(nums[cur] == 0 )
        {
            cur++;
        }else
        {
            swap(nums[dest+1],nums[cur]);
            dest++;
            cur++;
        }
    }
    }
};
